package cn.itsource.service.impl;

import cn.itsource.exception.GlobalException;
import cn.itsource.service.IUploadService;
import cn.itsource.template.CosTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
public class UploadServiceImpl implements IUploadService {

    @Autowired
    private CosTemplate cosTemplate ;

    //通用文件上传
    @Override
    public String uploadCos(MultipartFile file,String folder) {
        try {
            //获取的文件的扩展名
            String extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
            return cosTemplate.uploadForStream(file.getInputStream(),folder,extName);
            //FileUtil.extName()
        }catch (Exception e){
            throw new GlobalException("文件上传失败");
        }
    }





}
